#ifndef _RAYTRACE
#define _RAYTRACE

#include <math.h>
#include <scn.h>
#include <vector3.h>
#include <matrix4x4.h>
#include <transforms.h>
#include <render.h>
#include <visual.h>
#include <debug.h>
#include <stdio.h>
#include <stdlib.h>
#include <camera.h>
#include <scene.h>
#include <sphere.h>
#include <color.h>
#include <object.h>
#include <light.h>
#include <linkedlist.h>
#include <limits.h>

struct object_node{
  listnode_t node;
  object_t *object;
};

#define sqr( a ) pow2( a )
#define vector3_sqr( v ) vector3_dot( v, v )
#define vector3_distance( P1, P2 ) sqrt ( vector3_sqr( vector3_sub( P1, P2 ) ) )
#define COLOR_SHADE( color, z ) (color).a *= z; (color).r *= z; (color).g *= z; (color).b *= z;

/*

http://en.wikipedia.org/wiki/Ray_tracing

For each pixel in image {
  Create ray from eyepoint passing through this pixel
  Initialize NearestT to INFINITY and NearestObject to NULL

  For every object in scene {
     If ray intersects this object {
        If t of intersection is less than NearestT {
           Set NearestT to t of the intersection
           Set NearestObject to this object
        }
     }
  }

  If NearestObject is NULL {
     Fill this pixel with background color
  } Else {
     Shoot a ray to each light source to check if in shadow
     If surface is reflective, generate reflection ray: recurse
     If transparent, generate refraction ray: recurse
     Use NearestObject and NearestT to compute shading function
     Fill this pixel with color result of shading function
  }
}
*/

// simplified version of raytrace
void scene_raycast( scene_t *scene, camera_t camera );
// actual ray trace algorithim
void scene_raytrace( scene_t *scene, camera_t camera, linkedlist_t *ilumination );

#endif
